﻿using Assets.Script.Human.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Assets.Script.Human.Player.Config;
using Assets.Script.Tools;
using Script.NetSystem.Core;
using Script.UiSystem;
using UnityEngine;

namespace Assets.Script.BattleSystem.Core
{
    public class PlayerManager
    {
        /// <summary>
        /// key——玩家id
        /// value——玩家
        /// </summary>
        private Dictionary<int, NetPlayerController> palyers = new Dictionary<int, NetPlayerController>();
        
        public PlayerManager(RoleData[] roles)
        {
            GameObject player = Resources.Load<GameObject>(ResourcePath.Player);
            
            foreach (var role in roles)
            {
                GameObject go = GameObject.Instantiate(player);
                NetPlayerController manager = go.GetComponent<PlayerBody>().InitLocalPlayer(role);
                palyers[role.id] = manager;
            }
        }

        public void UpdatePlayerPos(int playerId, Vector3 pos)
        {
            if (playerId == GlobalCache.PlayerNetId)
            {
                return;
            }

            palyers[playerId].UpdatePos(pos);
        }


        public void CallPlayerAtkStart(int playerId, int killIndex)
        {
            if (playerId == GlobalCache.PlayerNetId)
            {
                return;
            }

            palyers[playerId].PlayerAtkStart(killIndex);
        }

        public void CallPlayerAtkEnd(int playerId)
        {
            if (playerId == GlobalCache.PlayerNetId)
            {
                return;
            }

            palyers[playerId].PlayerAtkEnd();
        }

        public void ChangePlayerHp(int playerId, float hp)
        {
            palyers[playerId].ChangePlayerHp(hp);
        }
        public void ChangePlayerMp(int playerId, float mp)
        {
            palyers[playerId].ChangePlayerMp(mp);
        }
        
    }
}
